package com.shiguo365.market.presenter.implement;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.display.view.IAddressAddView;
import com.shiguo365.market.presenter.contract.IAddressAddPresenter;

import java.util.Map;

import biz.yfsoft.api.ae.api.AEClient;
import biz.yfsoft.api.ae.api.AEParam;
import biz.yfsoft.api.ae.api.BaseAECallback;

/**
 * Created by caomenglong on 16/8/10.
 */
public class AddressAddPresenter implements IAddressAddPresenter {

    private static final String TAG = "AddressPresenter";
    private final Activity mActivity;
    private final IAddressAddView mAddressAddView;



    public AddressAddPresenter(@NonNull Activity activity, @NonNull IAddressAddView addressAddViewView) {
        this.mActivity = activity;
        this.mAddressAddView = addressAddViewView;
    }
    @Override
    public void addAddress(Integer uid, Map address) {
        AEClient _client = new AEClient("shiguo.user.addAddress");
        AEParam aeParam=new AEParam();
        aeParam.set("name",address.get("name"));
        aeParam.set("shopName",address.get("shopename"));
        aeParam.set("phone",address.get("phone"));
        aeParam.set("province",address.get("province"));
        aeParam.set("city",address.get("city"));
        aeParam.set("street",address.get("street"));
        aeParam.set("uid",address.get("uid"));
        aeParam.set("is_default",0);

        _client.call(aeParam,new BaseAECallback() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(JSONObject jsonObject) {
                Log.d(TAG,jsonObject.toString());
                mAddressAddView.OnAddAddressOk();
            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onFailure ......." + errno);
            }

            @Override
            public void onFinally(String s) {
                //mCartView.onGetCartFinished();
            }
        });
    }

}
